package main

import (
	"fmt"
	"log"
	"reflect"

	"./models"

	"github.com/astaxie/beego/orm"
	_ "github.com/lib/pq"
)

const (
	host     = "localhost"
	port     = 5432
	user     = "admin"
	password = "admin"
	dbname   = "test"
)

type Name struct {
	Id   int
	Name string
	Age  int
}

func main() {
	psqlInfo := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", host, port, user, password, dbname)
	var err error
	orm.RegisterDriver("postgres", orm.DRPostgres)
	orm.RegisterDataBase("default", "postgres", psqlInfo)
	orm.Debug = true
	if err != nil {
		log.Panicln(err)
	} else {
		log.Println("ok")
	}
	o := orm.NewOrm()
	o.Using("default")
	stu := new(models.Student)
	stu.Name = "tom"
	stu.Age = 25
	//	fmt.Println(o.Insert(stu))
	id, err := o.Insert(stu)
	log.Println("id type:", reflect.TypeOf(id))
	log.Println(id)

}
